package com.anytrek.cloudcommon.utils;

import com.github.pagehelper.PageInfo;
import lombok.extern.log4j.Log4j2;
import java.util.Collections;
import java.util.List;

@Log4j2
public class Tools {
    public static <T> ApiResult pageHelperResult(List<T> list, PageInfo<T> pageInfo, String TAG) {
        if (list.isEmpty()) {
            log.debug("{} : 获取列表为空 = {}", TAG, Collections.emptyList());
            return ApiResult.success("获取列表为空", Collections.emptyList());
        }
        PageData.PageDataBuilder<T> builder = PageData.builder();
        log.debug("{} : 获取列表成功 = {}", TAG, list);
        return ApiResult.success("获取列表成功", builder
                .totalNum(pageInfo.getTotal())
                .totalPage(pageInfo.getPages())
                .data(list)
                .build());
    }
}